/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-12-15
 * @Time  : 下午6:45
 * @brief :
 */
(function () {
    var Tip = require('wap_common:widget/ui/tip/tip.js').Tip,
        $page = $('.share-lottery'),
        loadingTip = new Tip({close:false,content:'正在准备……'}),
        commonTip = new Tip(),
        map;

    map = {
        7:{code:1,desc:'恭喜你抽到￥100红包'},
        4:{code:2,desc:'恭喜你抽到￥10000'},
        8:{code:3,desc:'恭喜你抽到￥50红包'},
        3:{code:4,desc:'恭喜你抽到￥5000提额券'},
        6:{code:5,desc:'恭喜你抽到+10%加息券'},
        2:{code:6,desc:'恭喜你抽到￥2000提额券'},
        1:{code:7,desc:'恭喜你抽到￥1000提额券'},
        5:{code:8,desc:'恭喜你抽到+5%加息券'}
    };

    $page.find('.lottery-icon').click(function(){
        loadingTip.show();
        $.get('/share/CouponGetDraw',function(ret,status){
            loadingTip.hide();
            if(ret.error_no == 0){
                var deg = 8*360,
                    id = ret.data.id;
                deg+=(map[id]['code']-1)*45;
                $page.find('.lottery-btn').css('-webkit-transform','rotate('+deg+'deg)');
                setTimeout(function(){
                    commonTip.on('click',function(){
                        location.href="/wap/gift";
                    }).show('' +
                        '<div>'+map[id]['desc']+'</div>' +
                        '<div style="margin-top:10px;"><a class="share-btn" style="padding:4px 0">查看奖品记录</a></div>'
                    );
                },5200);
            }else{
                commonTip.on('click',function(){
                    location.reload();
                }).show(ret.error_message);
            }
        },'json');
    });

    $page.find('.else-lottery-btn').click(function(){
        $page.find('.lottery-icon').trigger('click');
    })


})();